#include "recboxitem.h"
#include "ui_recboxitem.h"
#include<QPropertyAnimation>
#include<QDebug>
RecBoxItem::RecBoxItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RecBoxItem)
{
    ui->setupUi(this);
    ui->itemImageBox->installEventFilter(this);//下载捕捉器；
}

RecBoxItem::~RecBoxItem()
{
    delete ui;
}

bool RecBoxItem::eventFilter(QObject *watched, QEvent *event)
{
    //捕捉进入和出去的信号；
    if(watched == ui->itemImageBox)
    {
        if(event->type() == QEvent::Enter)
        {
            //创作动画；

            QPropertyAnimation*item = new QPropertyAnimation(ui->itemImageBox,"geometry");
            item->setDuration(150);
            item->setStartValue(QRect(9,9,ui->itemImageBox->width(),ui->itemImageBox->height()));
            item->setEndValue(QRect(9,0,ui->itemImageBox->width(),ui->itemImageBox->height()));
            item->start();
            //当动画结束时发送finish信号；
            connect(item,&QPropertyAnimation::finished,this,[=](){
               delete item;
            });
        }
        else if(event->type() == QEvent::Leave)
        {

            QPropertyAnimation*item = new QPropertyAnimation(ui->itemImageBox,"geometry");
            item->setDuration(150);
            item->setStartValue(QRect(9,0,ui->itemImageBox->width(),ui->itemImageBox->height()));
            item->setEndValue(QRect(9,9,ui->itemImageBox->width(),ui->itemImageBox->height()));
            item->start();
            //当动画结束时发送finish信号；
            connect(item,&QPropertyAnimation::finished,this,[=](){
               delete item;
            });
        }
    }
    return true;
}

void RecBoxItem::setImage(const QString &imagePath)
{
    ui->itemImageText->setStyleSheet("background-image:url("+imagePath+");");
}

void RecBoxItem::setRecText(const QString &text)
{
    ui->recText->setText(text);
}
